//
//  AppDelegate.m
//  HaoHint
//
//  Created by winter on 16/5/22.
//  Copyright © 2016年 wd. All rights reserved.
//

#import "AppDelegate.h"
#import "HHTabBarController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)setTabBarItem
{
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIFont systemFontOfSize:15],NSFontAttributeName, nil]
                                  forState:UIControlStateNormal];
}

- (void)registerPush
{
    UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
    UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:
                                                (UIUserNotificationTypeBadge |
                                                 UIUserNotificationTypeAlert |
                                                 UIUserNotificationTypeSound)
                                                                                 categories:[NSSet setWithObjects:categorys, nil]];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notiSettings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [application setStatusBarHidden:NO];
    
    [self registerPush];
    [self setTabBarItem];
    HHTabBarController *tabBar = [[HHTabBarController alloc] init];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:tabBar];
    [self.window makeKeyAndVisible];
    return YES;
}

//- (void)applicationDidEnterBackground:(UIApplication *)application
//{
//    NSArray *notis = [application scheduledLocalNotifications];
//    
//    for (UILocalNotification *noti in notis) {
//        NSLog(@"noti.userInfo = %@",noti.userInfo);
//    }
//}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
//    NSTimeInterval time = [notification.userInfo[@"localNotificationID"] floatValue];
//    NSTimeInterval preSeconds = [notification.userInfo[@"preSeconds"] floatValue];
//    NSTimeInterval seconds = [notification.userInfo[@"seconds"] floatValue];
//    
//    NSDate *fireDate = notification.fireDate;
//    NSDate *nowDate = [NSDate date];
//    
//    NSTimeInterval interval = [nowDate timeIntervalSinceDate:fireDate];
//    
//    NSLog(@"time = %f \n preSeconds = %f \n seconds = %f \n interval = %f",time,preSeconds,seconds,interval);
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidEnterBackgroundNotification object:nil];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillEnterForegroundNotification object:nil];
}
@end
